/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.etrs.formathlon.vue.jsf.form.user.suivi_formation;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import net.etrs.formathlon.entity.formation.Session;
import net.etrs.formathlon.entity.utilisateur.Avis;
import net.etrs.formathlon.persistance.formation.SessionFacade;
import net.etrs.formathlon.persistance.utilisateur.AvisFacade;
import net.etrs.formathlon.vue.jsf.utils.GeneralBean;

/**
 * Bean JSF pour la gestion de la vue Avis session. 
 * @author OPIF
 */
@ManagedBean
@ViewScoped
public class AvisSessionBean extends GeneralBean {
    
    private Session session;
    private Avis avis;
    @EJB
    private AvisFacade avisFacade;
    @EJB
    private SessionFacade sessionFacade;
    
    /**
     * Methode d'initialisation?
     */
    @PostConstruct
    public void init() {
        session = sessionFacade.newInstance();
        avis = avisFacade.newInstance();
        
    }

    /**
     * Constructeur par defaut.
     */
    public AvisSessionBean() {
    }
    
    /**
     * 
     * @return  avis
     */
    public Avis getAvis() {
        return avis;
    }
    
    /**
     * 
     * @param avis 
     */
    public void setAvis(Avis avis) {
        this.avis = avis;
    }
    
    /**
     * 
     * @return avisFacade
     */
    public AvisFacade getAvisFacade() {
        return avisFacade;
    }
    
    /**
     * 
     * @param avisFacade 
     */
    public void setAvisFacade(AvisFacade avisFacade) {
        this.avisFacade = avisFacade;
    }
    
    /**
     * 
     * @return session
     */
    public Session getSession() {
        return session;
    }
    
    /**
     * 
     * @param session 
     */
    public void setSession(Session session) {
        this.session = session;
    }
    
    /**
     * Action du bouton Valider du formulaire.
     * @return l'action de redirection JSF
     */
    public String valider() {
        avis.setSession(session);
        avisFacade.create(avis);
        displayMessage("Avis sauvegardé");
        return "goIndex";
    }
}
